package com.mytest.leetcode;

import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * Created by shixi  on 2020/1/17
 */
@Slf4j
public class Solution73 {

    public static void main(String[] args) {
        Solution73 solution121 = new Solution73();
        int [] nums = {2,4,7,3,5,9};
        int [] nums1 = new int[]{7,1,5,3,6,4};
//        int [ ][ ] arr={{1,1,1},{1,0,1},{1,1,1}};
//        int [ ][ ] arr={{0,1,2,0},{3,4,5,2},{1,3,1,5}};
        int [ ][ ] arr={{0,0,0,5},{4,3,1,4},{0,1,1,4},{1,2,1,3},{0,0,1,1}};
        int[][] merger ={nums,nums1};
        solution121.setZeroes(arr);

        log.info("{}",arr);
    }

    /**
     * [0,0,0,5],
     * [4,3,1,4],
     * [0,1,1,4],
     * [1,2,1,3],
     * [0,0,1,1]
     * @param matrix
     */
    public void setZeroes(int[][] matrix) {
        int rowCount = matrix.length;
        int clomnCount = matrix[0].length;

        Set<Integer> h = new HashSet<>();
        Set<Integer> l = new HashSet<>();

        for(int i=0;i< rowCount;i++) {
            for(int j=0;j< clomnCount;j++){
                if(matrix[i][j] == 0) {
                    h.add(i);
                    l.add(j);
                }
            }
        }


        // 行
        for(Integer ii:h){
            for(int k=0;k<clomnCount;k++){
                matrix[ii][k] = 0;
            }
        }

        // 列
        for(Integer ii:l){
//            log.info("ii:{}",ii);
            for(int g=0;g<rowCount;g++){
                matrix[g][ii] = 0;
            }
        }

        log.info("{},{}",h,l);
        log.info("{}",matrix);
    }
}
